package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.InvitationLabel;
import com.ruoyi.web.ydz.service.IInvitationLabelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 帖子标签Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/ydz/invlabel")
public class InvitationLabelController extends BaseController
{
    @Resource
    private IInvitationLabelService invitationLabelService;

    /**
     * 查询帖子标签列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:invlabel:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvitationLabel invitationLabel)
    {
        startPage();
        List<InvitationLabel> list = invitationLabelService.selectInvitationLabelList(invitationLabel);
        return getDataTable(list);
    }

    /**
     * 导出帖子标签列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:invlabel:export')")
    @Log(title = "帖子标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvitationLabel invitationLabel)
    {
        List<InvitationLabel> list = invitationLabelService.selectInvitationLabelList(invitationLabel);
        ExcelUtil<InvitationLabel> util = new ExcelUtil<InvitationLabel>(InvitationLabel.class);
        util.exportExcel(response, list, "帖子标签数据");
    }

    /**
     * 获取帖子标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:invlabel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invitationLabelService.selectInvitationLabelById(id));
    }

    /**
     * 新增帖子标签
     */
    @PreAuthorize("@ss.hasPermi('ydz:invlabel:add')")
    @Log(title = "帖子标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvitationLabel invitationLabel)
    {
        return toAjax(invitationLabelService.insertInvitationLabel(invitationLabel));
    }

    /**
     * 修改帖子标签
     */
    @PreAuthorize("@ss.hasPermi('ydz:invlabel:edit')")
    @Log(title = "帖子标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvitationLabel invitationLabel)
    {
        return toAjax(invitationLabelService.updateInvitationLabel(invitationLabel));
    }

    /**
     * 删除帖子标签
     */
    @PreAuthorize("@ss.hasPermi('ydz:invlabel:remove')")
    @Log(title = "帖子标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invitationLabelService.deleteInvitationLabelByIds(ids));
    }
}
